import { watcher } from "@feng3d/watcher";
import { SphereGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class SphereGeometry3D extends BufferGeometry3D
{
    radius = 1;
    widthSegments = 32;
    heightSegments = 16;
    phiStart = 0;
    phiLength = Math.PI * 2;
    thetaStart = 0;
    thetaLength = Math.PI;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new SphereGeometry(this.radius, this.widthSegments, this.heightSegments, this.phiStart, this.phiLength, this.thetaStart, this.thetaLength);
        }

        return this.__geometry;
    }
    declare protected __geometry: SphereGeometry;

    constructor()
    {
        super();

        watcher.watchs(this as SphereGeometry3D, ["radius", "widthSegments", "heightSegments", "phiStart", "phiLength", "thetaStart", "thetaLength"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as SphereGeometry3D, ["radius", "widthSegments", "heightSegments", "phiStart", "phiLength", "thetaStart", "thetaLength"], this._invalidate, this);
    }
}
